package com.xu.design.demo.factory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 *
 * @author xudenghui
 * @create 2023-07-31 16:22
 **/
public class JDKProxy {

    public  static <T> T getProxy(Class<T> interfaceClass,ICacheAdapter cacheAdapter){
        InvocationHandler handler = new JDKInvocationHandler(cacheAdapter);
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class<?>[] classes = interfaceClass.getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader, new Class[]{classes[0]}, handler);
        }
}
